import {
    toast
} from 'nc-lightapp-front';

import showReportTo from '../../request-functions/showReportTo';

import language from '../../language';

export default function () {

    const {
        editTable: {
            getClickRowIndex
        }
    } = this.props;

    const {
        humanResourceOrganizationValue: {
            refpk
        },
        clickRow
    } = this.state;
    
    let highLightRow = getClickRowIndex('ncc60071025list');

    if(!highLightRow) {
        highLightRow = clickRow;
    }

    if (highLightRow) {
        let postData = {
            func_type: 4,
            pk_org: refpk,
            pk_psnjob: highLightRow.record.values.pk_psnjob.value
        };

        showReportTo(postData)
            .then((res) => {
                if (res.success) {
                    const columns = res.data.table.map(item => {
                        return {
                            title: item.display,
                            dataIndex: item.key,
                            key: item.key
                        }
                    });
                    this.setState({
                        reptColumns: columns,
                        reptData: res.data.data,
                        reptObjVisible: true
                    });
                }
            });

    } else {
        toast({
            color: 'warning',
            content: language['hi6007-000066']/* 国际化处理： 请先点击你要查看的数据*/
        });
    }
}
